package cn.kduck.webapp;

import cn.kduck.core.web.json.JsonObject;
import cn.kduck.module.message.service.MailMessage;
import cn.kduck.module.message.service.MailMessageService;
import cn.kduck.module.message.service.SmsMessageService;
import cn.kduck.module.message.service.impl.MailMessageServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.spring.web.json.Json;

import java.io.File;
import java.util.UUID;

@RestController
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private MailMessageService mailMessageService;

    @Autowired
    private SmsMessageService smsMessageService;

    @GetMapping("/mail")
    public JsonObject sendMail(){
        MailMessage mailMessage = new MailMessage();
        mailMessage.setFromUserName("刘海刚");
        mailMessage.setTo("lhg317@163.com");
        mailMessage.setSubject("头像&照片");
        String cid = UUID.randomUUID().toString();
        mailMessage.setContent("<html><body>刘海刚之前用的头像：<p><img src='cid:"+ cid + "'></body></html>");
        mailMessage.addInline(cid,new File("D:\\User\\Pictures\\head.jpg"));

        mailMessage.addAttachment(new File("E:\\piclmk\\LMK_FC\\IMG_0138.JPG"));
        mailMessage.addAttachment(new File("E:\\piclmk\\LMK_FC\\IMG_0139.JPG"));
        mailMessage.addAttachment(new File("E:\\piclmk\\LMK_FC\\IMG_0167.JPG"));
        mailMessage.addAttachment(new File("E:\\piclmk\\LMK_FC\\IMG_0151.JPG"));
        mailMessage.addAttachment(new File("E:\\piclmk\\LMK_FC\\IMG_0161.JPG"));
        mailMessageService.sendMail(mailMessage);
        return JsonObject.SUCCESS;
    }

    @GetMapping("/sms")
    public JsonObject sendSms(){
        smsMessageService.sendMessage("13717741739","1435344","821005","5");
        return JsonObject.SUCCESS;
    }
}
